import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import type { Rule } from 'ant-design-vue/es/form'

/**
 * 获取字典类型表单验证规则
 * @returns 字典类型表单验证规则
 */
export const useTypeFormRules = () => {
  const { t } = useI18n()
  
  return computed<Record<string, Rule[]>>(() => ({
    dictName: [
      { required: true, message: t('dict.nameRequired'), trigger: 'blur' },
      { min: 2, max: 50, message: t('dict.nameLength'), trigger: 'blur' }
    ],
    dictType: [
      { required: true, message: t('dict.typeRequired'), trigger: 'blur' },
      { min: 2, max: 100, message: t('dict.typeLength'), trigger: 'blur' },
      { pattern: /^[a-zA-Z0-9_]+$/, message: t('dict.typePattern'), trigger: 'blur' }
    ],
    status: [
      { required: true, message: t('dict.statusRequired'), trigger: 'change' }
    ]
  }))
}

/**
 * 获取字典数据表单验证规则
 * @returns 字典数据表单验证规则
 */
export const useDataFormRules = () => {
  const { t } = useI18n()
  
  return computed<Record<string, Rule[]>>(() => ({
    dictLabel: [
      { required: true, message: t('dict.labelRequired'), trigger: 'blur' },
      { min: 2, max: 50, message: t('dict.labelLength'), trigger: 'blur' }
    ],
    dictValue: [
      { required: true, message: t('dict.valueRequired'), trigger: 'blur' },
      { min: 2, max: 100, message: t('dict.valueLength'), trigger: 'blur' }
    ],
    dictSort: [
      { required: true, message: t('dict.sortRequired'), trigger: 'blur' }
    ],
    status: [
      { required: true, message: t('dict.statusRequired'), trigger: 'change' }
    ]
  }))
} 